var app = angular.module('app', ['ngRoute']);
app.url = "http://127.0.0.1:8082";
//'+app.url+'
app.config(function ($routeProvider) {
    $routeProvider.when('/login', {
        templateUrl: 'login.html',
        controller: 'LoginCtrl',
    }).when('/activity', {
        templateUrl: 'activity.html',
        controller: 'activityCtrl',
        cache: 'true',
    }).when('/forum', {
        templateUrl: 'forum.html',
        controller: 'forumCtrl',
    }).when('/position', {
        templateUrl: 'position.html',
        controller: 'MapCtrl',
    }).when('/publishActivity', {
        templateUrl: 'publishActivity.html',
        controller: 'publishCtrl',
    }).when('/activityDetails/:aid', {
        templateUrl: 'activityDetails.html',
        controller: 'activityDetailsCtrl',
    }).when('/forumDetails/:fid', {
        templateUrl: 'forumDetails.html',
        controller: 'forumDetailsCtrl',
    }).when('/register', {
        templateUrl: 'register.html',
        controller: 'registerCtrl',
    }).when('/publishForum', {
        templateUrl: 'publishForum.html',
        controller: 'publishForumCtrl',
    }).when('/activitySearch/:searchContent', {
        templateUrl: 'activitySearch.html',
        controller: 'activitySearchCtrl',
    }).when('/forumSearch/:searchContent', {
        templateUrl: 'forumSearch.html',
        controller: 'forumSearchCtrl',
    }).when('/person', {
        templateUrl: 'person.html',
        controller: 'personCtrl',
    }).when('/myActivity', {
        templateUrl: 'myActivity.html',
        controller: 'myActivityCtrl',
    }).when('/myCollection', {
        templateUrl: 'myCollection.html',
        controller: 'myCollectionCtrl',
    }).when('/myForum', {
        templateUrl: 'myForum.html',
        controller: 'myForumCtrl',
    }).when('/feedback', {
        templateUrl: 'feedback.html',
        controller: 'feedbackCtrl',
    })
        .otherwise({
            redirectTo: '/login'
        });

});


//登录

// 适应手机输入
/*
 * 用户信息录入
 * */


app.controller('LoginCtrl', function ($scope, $location, $http, getUserAccountService) {
    $scope.password = null;
    $scope.login = function () {
        if (typeof($scope.username) == "undefined") {
            $.alertable.alert('账号不能为空!');
        } else {
            if (typeof($scope.password) == "undefined") {
                $.alertable.alert('密码不能为空!');
            } else {

                $scope.userid = $scope.username;
                $http({
                    method: 'post',
                    url: '' + app.url + '/yueqi/users/login',
                    data: {
                        "phone": $scope.username, "password": $scope.password
                    }
                }).then(function successCallback(response) {
                    $scope.user = response.data;
                    if ($scope.user.al == null) {
                        $scope.user.al = 0;
                    }
                    if ($scope.user.alc == null) {
                        $scope.user.alc = 0;
                    }
                    if ($scope.user.fl == null) {
                        $scope.user.fl = 0;
                    }
                    sessionStorage.setItem("user", JSON.stringify($scope.user));
                    $scope.user = JSON.parse(sessionStorage.getItem("user"));
                    if ($scope.user.uid != null) {
                        location.href = '#activity';
                    }
                    $location.path('/login');


                }, function errorCallback(response) {
                    $.alertable.alert("您的网络走丢了");
                });
            }

        }


    };

});


//b获取信息
app.controller('site', function ($scope, $http, getUserAccountService) {

    $scope.username = getUserAccountService.getAccount();

    $http({
        method: 'get',

        url: '' + app.url + '/yueqi/activities/all',

    }).then(function successCallback(response) {

        $scope.names = response.data.content;

    }, function errorCallback(response) {
    });

});

//活动
app.controller('activityCtrl', function ($scope, $http, getUserAccountService) {
    $scope.nickname = null;
    $scope.userage = null;
    $scope.names={};
    $scope.url = app.url;
    $scope.activity={};
    $scope.useraddress = null;
    $scope.userImg = null;
    $scope.userphone = null;
    $scope.userunderwrite = null;
if(JSON.parse(sessionStorage.getItem("user")!=null)){
    $scope.user = JSON.parse(sessionStorage.getItem("user"));
        $scope.username = $scope.user.uid;

        $scope.nickname = $scope.user.nickname;

        $scope.userage = $scope.user.age;

        $scope.useraddress = $scope.user.address;

        $scope.userImg = app.url + "/resources/img/"+$scope.user.imagePath;

        $scope.userunderwrite = $scope.user.underwrite;

        $scope.userphone = $scope.user.phone;

    if ($scope.user.al == 'null') {
        $scope.useractivitynum = 0;
    } else {
        $scope.useractivitynum = $scope.user.al;

    }

    if ($scope.user.alc == 'null') {
        $scope.usercollectnum = 0;
    } else {
        $scope.usercollectnum = $scope.user.alc;
    }

    if ($scope.user.fl == 'null') {
        $scope.userforumnum = 0;
    } else {
        $scope.userforumnum = 0;
        $scope.usercollectnum = 0;
        $scope.useractivitynum = 0;
    }
    }



    $http({
        method: 'get',
        url: '' + app.url + '/yueqi/forum/all',
    }).then(function successCallback(response) {
        $scope.names = response.data;

    }, function errorCallback(response) {
    });

$scope.judgement = true;


$('.panel').on('open', function () {
    $scope.judgement = false;
});
$scope.$watch("judgement", function () {
    if ($scope.judgement == false) {
        $scope.judgement == true;
    } else {
        $scope.judgement = false
    }
});

$('.panel').on('close', function () {

    $scope.judgement = true;
});

if (sessionStorage.getItem('userName') == null) {
    $scope.username = null;
}
else {
    $scope.username = sessionStorage.getItem('userName');
}

$http({
    method: 'get',
    url: '' + app.url + '/yueqi/activities/all',
}).then(function successCallback(response) {

    $scope.activity = response.data;

}, function errorCallback(response) {

});


$scope.all = true;
$scope.searchContent = null;
$scope.search = function () {
    $http({
        method: 'get',
        url: '' + app.url + '/yueqi/activities/' + $scope.searchContent + '/titles',

    }).then(function successCallback(response) {
        $scope.activity = response.data;

    }, function errorCallback(response) {

    });


};
$scope.allactivity = function () {
    $scope.all = true;
    $http({
        method: 'get',
        url: '' + app.url + '/yueqi/activities',
        cache: true,
    }).then(function successCallback(response) {
        $scope.activity = response.data;
    }, function errorCallback(response) {

    });

};

$scope.auto = function () {
    var mySwiper = new Swiper('.swiper-container', {
        speed: 500,
        autoplayDisableOnInteraction: false,
        autoplay: 1000, //// 为啥这个参数无效
        //是够能够循环无缝滑动
        grabCursor: true,
        paginationClickable: true //允许触摸

    });
    location.replace(location);
    $('.swiper-slide').css('width', $(window).width());
    console.log($(window).width());
};

})
;


//论坛

app.controller('forumCtrl', function ($scope, $http, getUserAccountService) {

    $scope.nickname = null;
    $scope.userage = null;
    $scope.useraddress = null;
    $scope.userImg = null;
    $scope.userphone = null;
    $scope.userunderwrite = null;
    $scope.url = app.url;
    $scope.user = JSON.parse(sessionStorage.getItem("user"));

    if ($scope.user != 'null') {
        $scope.username = $scope.user.uid;
        if ($scope.username != null) {

        }
        $scope.nickname = $scope.user.nickname;
        $scope.userAge = $scope.user.age;
        $scope.useraddress = $scope.user.address;
        $scope.userImg = app.url+ $scope.user.imagePath;
        $scope.userphone = $scope.user.phone;
        $scope.userunderwrite = $scope.user.underwrite;
        if ($scope.user.al == 'null') {
            $scope.useractivitynum = 0;
        } else {
            $scope.useractivitynum = $scope.user.al;

        }

        if ($scope.user.alc == 'null') {
            $scope.usercollectnum = 0;
        } else {
            $scope.usercollectnum = $scope.user.alc;
        }

        if ($scope.user.fl == 'null') {
            $scope.userforumnum = 0;
        } else {
            $scope.userforumnum = $scope.user.fl;
        }


    }

    $http({
        method: 'get',
        url: '' + app.url + '/yueqi/forum/all',
    }).then(function successCallback(response) {
        $scope.names = response.data;

    }, function errorCallback(response) {
    });



});

//发帖
app.controller('publishForumCtrl', function ($scope, $http, getUserAccountService) {
    console.log( JSON.parse(sessionStorage.getItem("user")).uid)

    $scope.url=app.url;
    //隐藏了input:file样式后，点击头像就可以本地上传
    $(".addpic").click(function () {
        $('#addfile').click();
    $('#addfile').change(function () {
            var formData=new FormData($('.uplodefile')[0]);
            $.ajax({
                url: app.url + "/file/imageUpload",
                type: "post",
                data: formData,
                contentType: false,
                processData: false,
                success: function (result) {
                    console.log(result)
                    $scope.imgPath=result;
                        $(".img").val($scope.imgPath);
                        $("#pic").attr("src",app.url+$scope.imgPath)
                },
                error: function (result) {

                }
            });


    });
    })
    //点击发布帖子
    $scope.pushforum = function () {
        $http({
            method: 'post',
            url: '' + app.url + '/yueqi/users/userforum/save',
            data: {
                "uid": JSON.parse(sessionStorage.getItem("user")).uid,
                "title": $scope.forumTitle,
                "content": $scope.forumContent,
                "imgPath": $scope.imgPath,
            }
        }).then(function successCallback(response) {

window.location.href="#forum"
            //回调函数中上传图片
        }, function errorCallback(response) {
            alert("网络故障 ")
        });
    };

});

app.controller('feedbackCtrl', function ($scope, $http, getUserAccountService) {

    $scope.pushquestion = function () {
        $http({
            method: 'post',
            url: '' + app.url + '/yueqi/questions',
            data: {
                "questions": $scope.questionContent,
            }
        }).then(function successCallback(response) {
            $.alertable.alert("提交");
        }, function errorCallback(response) {
            alert("网络故障")
        });

    }
});
/*
 app.controller('feedbackCtrl', function($scope, $http, getUserAccountService) {
 $scope.username=getUserAccountService.getAccount();
 //点击提交问题
 $scope.pushquestion = function() {
 alert($scope.questionContent)
 $http({
 method: 'post',
 url: ''+app.url+'/yueqi/users/questions',
 data: {
 "questions":$scope.questionContent,
 }
 }).then(function successCallback(response) {
 console.log(response.data.msg)
 }, function errorCallback(response) {
 alert(2)
 });
 };
 }});*/
//地图
app.controller('MapCtrl', function ($scope, getUserAccountService) {
    //三个数量信息
    $scope.nickname = null;
    $scope.userage = null;
    $scope.useraddress = null;
    $scope.userImg = null;
    $scope.userphone = null;
    $scope.userunderwrite = null;
    $scope.user = JSON.parse(sessionStorage.getItem("user"));

    if ($scope.user != 'null') {
        $scope.username = $scope.user.uid;
        if ($scope.username != null) {

        }
        $scope.nickname = $scope.user.nickname;
        $scope.userAge = $scope.user.age;
        $scope.useraddress = $scope.user.address;
        $scope.userImg = app.url+"resources/img/" + $scope.user.imagePath;
        $scope.userphone = $scope.user.phone;
        $scope.userunderwrite = $scope.user.underwrite;
        if ($scope.user.al == 'null') {
            $scope.useractivitynum = 0;
        } else {
            $scope.useractivitynum = $scope.user.al;

        }

        if ($scope.user.alc == 'null') {
            $scope.usercollectnum = 0;
        } else {
            $scope.usercollectnum = $scope.user.alc;
        }

        if ($scope.user.fl == 'null') {
            $scope.userforumnum = 0;
        } else {
            $scope.userforumnum = $scope.user.fl;
        }


    }


    var map = new BMap.Map("allmap");
    map.centerAndZoom("成都", 12);
    map.enableScrollWheelZoom();    //启用滚轮放大缩小，默认禁用
    map.enableContinuousZoom();    //启用地图惯性拖拽，默认禁用

    map.addControl(new BMap.NavigationControl());  //添加默认缩放平移控件
    map.addControl(new BMap.OverviewMapControl()); //添加默认缩略地图控件
    map.addControl(new BMap.OverviewMapControl({isOpen: true, anchor: BMAP_ANCHOR_BOTTOM_RIGHT}));   //右下角，打开

    var localSearch = new BMap.LocalSearch(map);
    localSearch.enableAutoViewport(); //允许自动调节窗体大小


    $scope.searchMap = function () {
        console.log("1")
        map.clearOverlays();//清空原来的标注
        var keyword = document.getElementById("search-position").value;
        localSearch.setSearchCompleteCallback(function (searchResult) {
            var poi = searchResult.getPoi(0);

            var geolocation = new BMap.Geolocation();
            geolocation.getCurrentPosition(function (r) {
                if (this.getStatus() == BMAP_STATUS_SUCCESS) {
                    var mk = new BMap.Marker(r.point);
                    map.addOverlay(mk);
                    map.panTo(r.point);

                    var start1 = r.point.lng;
                    var start2 = r.point.lat;
                    <!--维度-精度-->

                    var p1 = new BMap.Point(start1, start2);
                    var p2 = new BMap.Point(poi.point.lng, poi.point.lat);

                    var driving = new BMap.DrivingRoute(map, {renderOptions: {map: map, autoViewport: true}});
                    driving.search(p1, p2);
                }
                else {
                    alert('failed' + this.getStatus());
                }
            }, {enableHighAccuracy: true})
        });
        localSearch.search(keyword);

    };
    $scope.setsearch = function () {
        setInterval($scope.searchMap, 5000)
    }
});


//发布活动

app.controller('publishCtrl', function ($scope, $location, $http, getUserAccountService) {
    $scope.url=app.url;
    $scope.nickname = null;
    $scope.userage = null;
    $scope.useraddress = null;
    $scope.userImg = null;
    $scope.userphone = null;
    $scope.userunderwrite = null;
    $scope.user = JSON.parse(sessionStorage.getItem("user"));

    if ($scope.user != 'null') {
        $scope.username = $scope.user.uid;
        if ($scope.username != null) {

        }
        $scope.nickname = $scope.user.nickname;
        $scope.userAge = $scope.user.age;
        $scope.useraddress = $scope.user.address;
        $scope.userImg = app.url+ $scope.user.imagePath;
        $scope.userphone = $scope.user.phone;
        $scope.userunderwrite = $scope.user.underwrite;
        if ($scope.user.al == 'null') {
            $scope.useractivitynum = 0;
        } else {
            $scope.useractivitynum = $scope.user.al;

        }

        if ($scope.user.alc == 'null') {
            $scope.usercollectnum = 0;
        } else {
            $scope.usercollectnum = $scope.user.alc;
        }

        if ($scope.user.fl == 'null') {
            $scope.userforumnum = 0;
        } else {
            $scope.userforumnum = $scope.user.fl;
        }


    }
    $(".addpic").click(function () {
        $('#addfile').click();
        $('#addfile').change(function () {
            var formData=new FormData($('.uplodefile')[0]);
            $.ajax({
                url: app.url + "/file/imageUpload",
                type: "post",
                data: formData,
                contentType: false,
                processData: false,
                success: function (result) {
                    console.log(result)
                    $scope.activity.imagePath=result;
                    $(".img").val($scope.activity.imagePath);
                    $("#pic").attr("src",app.url+$scope.activity.imagePath)
                },
                error: function (result) {

                }
            });


        });
    })





    $scope.push = function () {
        $http({
            method: 'post',
            url: '' + app.url + '/yueqi/activities/save',
            data: {
                "headLine": $scope.activity.title,
                "startTime": $scope.activity.Stime,
                "endTime": $scope.activity.Etime,
                "activityRoute": $scope.activity.Position,
                "contact": $scope.activity.phone,
                "detials": $scope.activity.detials,
                "userCount": $scope.activity.num,
                "imagePath": $scope.activity.imagePath,
                "uid": $scope.username
            }
        }).then(function successCallback(response) {

        window.location.href="#activity"
            //回调函数中上传图片
        }, function errorCallback(response) {
            alert(2)
        });
    };
});

//活动详情
app.controller('activityDetailsCtrl', function ($scope, $routeParams, $location, $http, getUserAccountService) {
    $scope.user = JSON.parse(sessionStorage.getItem("user"));
    if (sessionStorage.getItem('userName') == null) {
        $scope.username = null;
        $("#join").css("background", "#88817e");
        $("#join>button").attr('disabled', true);
        $("#join>button").html("未登录");
        $("#gooded").attr("onclick", null);
    }

    $scope.aid = false;
    $scope.url = app.url;
    $scope.gooded = "img/good-ioc.png"
    $scope.params = $routeParams;
    //判断是否已收藏'+app.url+'/yueqi/users/
    if ($scope.username != null) {
        $http({
            method: 'GET',
            url: '' + app.url + '/yueqi/users/' + $scope.username
        }).then(function successCallback(response) {

            console.log(response.data);
            for (var i = 0; i < response.data.collectActivities.length; i++) {
                if (response.data.collectActivities[i].aid == $scope.params.aid) {
                    $scope.aid = true;
                    $scope.gooded = "img/gooded-ioc.png";

                }
            }
            if (response.data.joinActivities.length > 0) {
                if (response.data.joinActivities[i].aid == $scope.params.aid) {

                    $("#join").css("background", "#88817e");
                    $("#join>button").attr('disabled', true);
                    $("#join>button").html("已经报名");

                }


            }


        }, function errorCallback(response) {
            // 请求失败执行代码
        });
    }


    $http({
        method: 'GET',
        url: '' + app.url + '/yueqi/activities/find/' + $scope.params.aid
    }).then(function successCallback(response) {
        // console.log(response.data);
        $scope.activity = response.data;

    }, function errorCallback(response) {
        // 请求失败执行代码
    });

    /*$http({
     method: 'GET',
     url: ''+app.url+'/yueqi/users/'+$scope.params.aid
     }).then(function successCallback(response) {

     $scope.activity = response.data;
     console.log($scope.activity)
     }, function errorCallback(response) {
     // 请求失败执行代码
     });*/

    $scope.collection = function () {
        if ($scope.username) {
            $scope.aid = true;

            $http({
                method: 'post',
                url: '' + app.url + '/yueqi/users/collection',
                data: {
                    "uid": $scope.username,
                    "aid": $scope.params.aid
                }
            }).then(function successCallback(response) {
                if (response.data.msg = "成功") {
                    $.alertable.alert("收藏成功");
                }
            }, function errorCallback(response) {
                // 请求失败执行代码
            });
        } else {

            $location.path('/login');
            ;
        }


    };

    $scope.join = function () {

        $http({
            method: 'post',
            url: '' + app.url + '/yueqi/users/join',
            data: {
                "uid": $scope.username, "aid": $scope.params.aid
            }
        }).then(function successCallback(response) {
            console.log(response.data.msg);
            if (response.data.msg == "成功");
            {
                $("#join").css("background", "#88817e");
                $("#join>button").attr('disabled', true);
                $("#join>button").html("已经报名");

                $scope.useractivitynum = sessionStorage.getItem('useractivitynum');
                console.log(sessionStorage.getItem('useractivitynum'));
                $scope.useractivitynum = sessionStorage.setItem('useractivitynum', $scope.useractivitynum);

            }

        }, function errorCallback(response) {
            // 请求失败执行代码
        });


    }


});
//论坛详情
app.controller('forumDetailsCtrl', function ($scope, $routeParams, $location, $http, getUserAccountService) {

    $scope.username = getUserAccountService.getAccount();
    $scope.params = $routeParams;
    $scope.url = app.url;
    //获取时间
    $scope.gettime = function () {
        var date = new Date();
        var year = date.getFullYear(); //获取当前年份
        var mon = date.getMonth() + 1; //获取当前月份
        var da = date.getDate(); //获取当前日
        $scope.thistime = year + '年' + mon + '月' + da + '日';

    };
    $scope.gettime();
    $scope.reply = function () {
        //发布回复
        $http({
            method: 'post',
            url: '' + app.url + '/yueqi/comments',
            data: {
                "content": $scope.replycomment,
                "fid": $scope.params.fid

            }
        }).then(function successCallback(response) {
//成功后在请求
            //刷新回复
            $http({
                method: 'GET',
                url: '' + app.url + '/yueqi/forum/find/' + $scope.params.fid
            }).then(function successCallback(response) {
                $scope.replycomment = "";
                $scope.replys = response.data.comment;
            }, function errorCallback(response) {
                // 请求失败执行代码
            });
            /*/forumDetails/:fid*/
        }, function errorCallback(response) {
            // 请求失败执行代码
        });
    };

    //帖子的title和内容
    $http({
        method: 'GET',
        url: '' + app.url + '/yueqi/forum/find/' + $scope.params.fid
    }).then(function successCallback(response) {

        $scope.forumss = response.data;
        $scope.replys = response.data.comment;
    }, function errorCallback(response) {
        // 请求失败执行代码
    });
    //初次查看回复
    /*  $http({
     method: 'GET',
     url: ''+app.url+'/yueqi/forums/' + $scope.params.fid
     }).then(function successCallback(response) {
     $scope.replys = response.data.comment;
     }, function errorCallback(response) {
     // 请求失败执行代码
     });*/
//发帖人的信息+帖子内容
    $http({
        method: 'GET',
        url: '' + app.url + '/yueqi/forums'
    }).then(function successCallback(response) {
        //帖子的信息
        $scope.forums = response.data;
        for (var i = 0; i < $scope.forums.length; i++) {
            //发帖人的信息
            if ($scope.forums[i].fid == $scope.params.fid) {
                $scope.forumdetailes = $scope.forums[i]
            }
        }
    }, function errorCallback(response) {
        // 请求失败执行代码
    });

});

//注册
app.controller('registerCtrl', function ($scope, $http, $location, getUserAccountService) {

    $scope.register = function () {
        if (typeof($scope.user.Username) == "undefined" || typeof($scope.user.Password) == "undefined" || typeof($scope.user.RePassword) == "undefined") {
            alert("请先填完整注册信息！")
        } else if ($scope.user.Password != $scope.user.RePassword) {
            alert("两次输入的密码不一致")
        } else {
            $http({
                method: 'post',
                url: '' + app.url + '/yueqi/register',
                data: {
                    "uid": $scope.user.Username,
                    "password": $scope.user.Password
                }
            }).then(function successCallback(response) {
                $.alertable.alert(response.data);
                if (response.data == '注册成功') {
                    $location.path('/login');
                }

            }, function errorCallback(response) {
                $.alertable.alert(response);
            });
        }
    };


});


//帖子搜索详情
app.controller('forumSearchCtrl', function ($scope, $routeParams, $http, getUserAccountService) {
    $scope.username = getUserAccountService.getAccount();
    $scope.params = $routeParams;

    $http({
        method: 'get',
        url: '' + app.url + '/yueqi/forums/' + $scope.params.searchContent + '/titles',
    }).then(function successCallback(response) {
        $scope.searchcont = response.data
        if ($scope.searchcont.length == 0) {
            $scope.searchcontresulenull = "无数据"
        }
        $scope.params.fid = $scope.searchcont[0].fid
        $http({
            method: 'GET',
            url: '' + app.url + '/yueqi/forums/all'
        }).then(function successCallback(response) {
            $scope.forums = response.data;
            for (var i = 0; i < $scope.forums.length; i++) {

                if ($scope.forums[i].fid == $scope.params.fid) {
                    $scope.forumsearch = $scope.forums[i]
                }
            }

        }, function errorCallback(response) {
            // 请求失败执行代码
        });

        console.log($scope.searchcont)
    }, function errorCallback(response) {

    });
});


//修改资料
app.controller('personCtrl', function ($scope, $http, getUserAccountService) {
        $scope.nickname = null;
        $scope.userage = null;
        $scope.useraddress = null;
        $scope.userImg = null;
        $scope.userphone = null;
        $scope.userunderwrite = null;
        $scope.user = JSON.parse(sessionStorage.getItem("user"));
        if ($scope.user != 'null') {
            $scope.username = $scope.user.uid;
            if ($scope.username != null) {
            }
            $scope.nickname = $scope.user.nickname;
            $scope.userAge = $scope.user.age;
            $scope.useraddress = $scope.user.address;
            $scope.userImg = "127.0.0.1/resources/img/" + $scope.user.imagePath;
            $scope.userphone = $scope.user.phone;
            $scope.userunderwrite = $scope.user.underwrite;
            if ($scope.user.al == 'null') {
                $scope.useractivitynum = 0;
            } else {
                $scope.useractivitynum = $scope.user.al;

            }

            if ($scope.user.alc == 'null') {
                $scope.usercollectnum = 0;
            } else {
                $scope.usercollectnum = $scope.user.alc;
            }

            if ($scope.user.fl == 'null') {
                $scope.userforumnum = 0;
            } else {
                $scope.userforumnum = $scope.user.fl;
            }


        }


        $scope.reader = new FileReader();
        var canvas;
        $scope.img_upload = function (files) {

            $scope.reader.readAsDataURL(files[0]);  //FileReader的方法，把图片转成base64
            var objUrl = getObjectURL(files[0]);
            var img = new Image();
            //获取预览画布
            canvas = document.createElement('canvas');
            canvas.width = 200;
            canvas.height = 200;
            $('#ss').attr('src', objUrl);
        };

        $scope.reader.onload = function (ev) {
            $scope.$apply(function () {

                var img = ev.target.result;//接收base64
                var data = canvas.toDataURL();
                img = img.replace("data:image/png;base64,", '');
                img = img.replace("data:image/jpg;base64,", '');
                img = img.replace("data:image/jpeg;base64,", '');

                console.log(data);


                if (img != null) {
                    $http({
                        method: 'POST',
                        url: '' + app.url + '/yueqi/users/upload',
                        data: {
                            'imagePath': img,
                            'uid': $scope.username
                        },


                    }).then(function successCallback(response) {
                        //上传成功的操作
                        console.log(response.data.msg);

                    }, function () {

                    });
                }
            });
        };

//建立一個可存取到該file的url
        function getObjectURL(file) {
            var url = null;
            if (window.createObjectURL != undefined) { // basic
                url = window.createObjectURL(file);
            } else if (window.URL != undefined) { // mozilla(firefox)
                url = window.URL.createObjectURL(file);
            } else if (window.webkitURL != undefined) { // webkit or chrome
                url = window.webkitURL.createObjectURL(file);
            }
            return url;
        }

        $scope.save1 = function () {
//上传图片


        };

        $scope.logOut = function () {
            sessionStorage.removeItem('userName');
            sessionStorage.removeItem('userImg');
            sessionStorage.removeItem('userUnderwrite');
            sessionStorage.removeItem('userNickname');
            sessionStorage.removeItem('userAge');
            sessionStorage.removeItem('userPhone');
            sessionStorage.removeItem('userPassword');
            sessionStorage.removeItem('userAddress');
            sessionStorage.removeItem('userGender');
            location.href = '#activity';
        };

        $('#gender').focus(function () {
            $scope.sex = '';
            $(this).val('');
        });

        $scope.uploadchange = function () {
            if ($scope.sex == "男") {
                $scope.userGender = "0"
            }
            if ($scope.sex == "女") {
                $scope.userGender = "1"
            }
            console.log($scope.userGender);
            //上传信息
            $http({
                method: 'post',
                url: '' + app.url + '/yueqi/users/setting',
                data: {
                    "uid": $scope.username,
                    "password": $scope.userPassword,
                    "nickname": $scope.nickname,
                    "underwrite": $scope.underwrite,
                    "gender": $scope.userGender,
                    "age": $scope.userAge,
                    "address": $scope.userAddress,
                    "phone": $scope.userPhone,
                }
            }).then(function successCallback(response) {

                $scope.remsg = response.data.msg;
                if ($scope.remsg == "成功") {


                    /*获得用户信息*/
                    $http({
                        method: 'get',
                        url: '' + app.url + '/yueqi/users/' + $scope.username,

                    }).then(function successCallback(response) {

                        console.log(response.data);
                        if (response.data.imagePath == null) {
                            console.log("图片为空");
                            sessionStorage.setItem('userImg', 'image');
                        } else {
                            sessionStorage.setItem('userImg', "'+app.url+'/yueqi/images/" + response.data.imagePath);
                        }
                        console.log(sessionStorage.getItem('userImg'));

                        if (response.data.gender == null) {
                            sessionStorage.setItem('userGender', 'gender');
                        } else if (response.data.gender == 0) {
                            sessionStorage.setItem('userGender', '男');

                        } else if (response.data.gender == 1) {
                            sessionStorage.setItem('userGender', '女');
                        }

                        if (response.data.age == null) {

                            sessionStorage.setItem('userAge', 'userAge');
                        } else {
                            sessionStorage.setItem('userAge', response.data.age);
                        }

                        if (response.data.nickname == null) {
                            sessionStorage.setItem('userNickname', 'userNickname');
                        } else {
                            sessionStorage.setItem('userNickname', response.data.nickname);
                        }

                        if (response.data.phone == null) {
                            sessionStorage.setItem('userPhone', 'userPhone');
                        } else {
                            sessionStorage.setItem('userPhone', response.data.phone);
                        }
                        if (response.data.underwrite == null) {
                            sessionStorage.setItem('userUnderwrite', 'userUnderwrite');
                        } else {
                            sessionStorage.setItem('userUnderwrite', response.data.underwrite);
                        }

                        if (response.data.address == null) {
                            sessionStorage.setItem('userAddress', 'userAddress');
                        } else {
                            sessionStorage.setItem('userAddress', response.data.address);
                        }
                        sessionStorage.setItem('userPassword', $scope.password);
                        if (response.data.uid == null) {
                            sessionStorage.setItem('userName', $scope.username);
                        } else {
                            sessionStorage.setItem('userName', response.data.uid);
                        }


                        console.log("'+app.url+'/yueqi/images/" + response.data.imagePath);
                    }, function errorCallback(response) {
                        $.alertable.alert("网络太忙了");
                    });
                    $.alertable.alert('修改成功');
                }

            }, function errorCallback(response) {

            });
            $(function () {
                $('#underwrite').attr('disabled', true);
                $('#gender').attr('disabled', true);
                $('#age').attr('disabled', true);
                $('#address').attr('disabled', true);
                $('#phone').attr('disabled', true);
            });
        }

    }
);

//我的活动
app.controller('myActivityCtrl', function ($scope, $http, getUserAccountService) {

    $scope.username = sessionStorage.getItem('userName');
    $http({
        method: 'get',
        url: '' + app.url + '/yueqi/users/' + $scope.username,
    }).then(function successCallback(response) {


        $scope.myjoinactivity = response.data.joinActivities;
        console.log(response.data.joinActivities);
        if ($scope.myjoinactivity.length == 0) {
            $scope.myactivityresultnull = "无数据"
        }
        if ($scope.myjoinactivity.length == 0) {
            $scope.joinactivityresultnull = "无数据"
        }
    }, function errorCallback(response) {
    });
});


//我的收藏
app.controller('myCollectionCtrl', function ($scope, $http, getUserAccountService) {
    $scope.username = sessionStorage.getItem('userName');
    $http({
        method: 'get',
        url: '' + app.url + '/yueqi/users/' + $scope.username,
    }).then(function successCallback(response) {

        $scope.myconllection = response.data.collectActivities
        if ($scope.myconllection.length == 0) {
            $scope.myconllectionresultnull = "我还没有收藏任何活动"
        }
    }, function errorCallback(response) {
    });
});


//我的帖子
app.controller('myForumCtrl', function ($scope, $http, getUserAccountService) {


    $scope.userPassword = sessionStorage.getItem('userPassword');
    $http({
        method: 'get',
        url: '' + app.url + '/yueqi/users/' + $scope.username,
    }).then(function successCallback(response) {

        $scope.myForum = response.data.userForum;
        console.log($scope.myForum);
        $http({
            method: 'get',
            url: '' + app.url + '/yueqi/forums/all',
        }).then(function successCallback(response) {

            $scope.forums = response.data;
            for (var i = 0; i < $scope.forums.length; i++) {
                if ($scope.myForum[0].fid == $scope.forums[i].fid) {
                    $scope.forumsearch = $scope.forums[i];
                }
            }
        }, function errorCallback(response) {
        });


    }, function errorCallback(response) {
    });
});
// });